1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
|
"use client"
import * as React from "react"
import { Button } from "@/components/ui/button"
import { Card } from "@/components/ui/card"
import { Checkbox } from "@/components/ui/checkbox"
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react"
import {
getCoreRowModel,
getFilteredRowModel,
getPaginationRowModel,
getSortedRowModel,
useReactTable,
type ColumnDef,
} from "@tanstack/react-table"
import { DataTable } from "@/components/data-table/data-table"
// 프로젝트 AVL 데이터 타입
type ProjectAvlItem = {
id: string
no: number
designCategory: string
customerAvlMaterialName: string
materialGroupInfo: string
avlVendorName: string
vendorInfo: string
ownerSuggestion: string
shiSuggestion: string
}
// 선종별 표준 AVL 데이터 타입
type StandardAvlItem = {
id: string
no: number
designCategory: string
avlVendorName: string
materialGroupInfo: string
vendorInfo: string
headquarterLocation: string
tier: string
}
// Vendor Pool 데이터 타입
type VendorPoolItem = {
id: string
no: number
designCategory: string
avlVendorName: string
materialGroupInfo: string
vendorInfo: string
vendorClassification: string
faStatus: string
recentQuoteNumber: string
recentOrderNumber: string
}
// Mock 데이터들
const mockProjectAvlData: ProjectAvlItem[] = [
{
id: "p1",
no: 1,
designCategory: "엔진",
customerAvlMaterialName: "메인엔진",
materialGroupInfo: "엔진부품",
avlVendorName: "엔진업체A",
vendorInfo: "국내 엔진 전문업체",
ownerSuggestion: "승인",
shiSuggestion: "승인",
},
]
const mockStandardAvlData: StandardAvlItem[] = [
{
id: "s1",
no: 1,
designCategory: "케이블",
avlVendorName: "케이블업체A",
materialGroupInfo: "전기부품",
vendorInfo: "국내 케이블 제조사",
headquarterLocation: "한국",
tier: "Tier 1",
},
]
const mockVendorPoolData: VendorPoolItem[] = [
{
id: "v1",
no: 1,
designCategory: "펌프",
avlVendorName: "펌프업체A",
materialGroupInfo: "기계부품",
vendorInfo: "국제 펌프 제조사",
vendorClassification: "주요업체",
faStatus: "완료",
recentQuoteNumber: "Q2024001",
recentOrderNumber: "PO2024001",
},
]
// 프로젝트 AVL 테이블 컬럼
const projectAvlColumns: ColumnDef<ProjectAvlItem>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row, table }) => {
// 프로젝트 AVL 테이블의 단일 선택 핸들러
const handleRowSelection = (checked: boolean) => {
if (checked) {
// 다른 모든 행의 선택 해제
table.getRowModel().rows.forEach(r => {
if (r !== row && r.getIsSelected()) {
r.toggleSelected(false)
}
})
}
// 현재 행 선택/해제
row.toggleSelected(checked)
}
return (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={handleRowSelection}
aria-label="Select row"
/>
)
},
enableSorting: false,
enableHiding: false,
size: 50,
},
{
accessorKey: "no",
header: "No.",
size: 60,
},
{
accessorKey: "designCategory",
header: "설계공종",
size: 120,
},
{
accessorKey: "customerAvlMaterialName",
header: "고객사 AVL 자재명",
size: 150,
},
{
accessorKey: "materialGroupInfo",
header: "자재그룹 정보",
size: 130,
},
{
accessorKey: "avlVendorName",
header: "AVL 등재업체명",
size: 140,
},
{
accessorKey: "vendorInfo",
header: "협력업체 정보",
size: 130,
},
{
accessorKey: "ownerSuggestion",
header: "선주제안",
size: 100,
},
{
accessorKey: "shiSuggestion",
header: "SHI 제안",
size: 100,
},
]
// 선종별 표준 AVL 테이블 컬럼
const standardAvlColumns: ColumnDef<StandardAvlItem>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row, table }) => {
// 선종별 표준 AVL 테이블의 단일 선택 핸들러
const handleRowSelection = (checked: boolean) => {
if (checked) {
// 다른 모든 행의 선택 해제
table.getRowModel().rows.forEach(r => {
if (r !== row && r.getIsSelected()) {
r.toggleSelected(false)
}
})
}
// 현재 행 선택/해제
row.toggleSelected(checked)
}
return (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={handleRowSelection}
aria-label="Select row"
/>
)
},
enableSorting: false,
enableHiding: false,
size: 50,
},
{
accessorKey: "no",
header: "No.",
size: 60,
},
{
accessorKey: "designCategory",
header: "설계공종",
size: 120,
},
{
accessorKey: "avlVendorName",
header: "AVL 등재업체명",
size: 140,
},
{
accessorKey: "materialGroupInfo",
header: "자재그룹 정보",
size: 130,
},
{
accessorKey: "vendorInfo",
header: "협력업체 정보",
size: 130,
},
{
accessorKey: "headquarterLocation",
header: "본사 위치 (국가)",
size: 140,
},
{
accessorKey: "tier",
header: "등급 (Tier)",
size: 120,
},
]
// Vendor Pool 테이블 컬럼
const vendorPoolColumns: ColumnDef<VendorPoolItem>[] = [
{
id: "select",
header: ({ table }) => (
<Checkbox
checked={
table.getIsAllPageRowsSelected() ||
(table.getIsSomePageRowsSelected() && "indeterminate")
}
onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)}
aria-label="Select all"
/>
),
cell: ({ row, table }) => {
// Vendor Pool 테이블의 단일 선택 핸들러
const handleRowSelection = (checked: boolean) => {
if (checked) {
// 다른 모든 행의 선택 해제
table.getRowModel().rows.forEach(r => {
if (r !== row && r.getIsSelected()) {
r.toggleSelected(false)
}
})
}
// 현재 행 선택/해제
row.toggleSelected(checked)
}
return (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={handleRowSelection}
aria-label="Select row"
/>
)
},
enableSorting: false,
enableHiding: false,
size: 50,
},
{
accessorKey: "no",
header: "No.",
size: 60,
},
{
accessorKey: "designCategory",
header: "설계공종",
size: 120,
},
{
accessorKey: "avlVendorName",
header: "AVL 등재업체명",
size: 140,
},
{
accessorKey: "materialGroupInfo",
header: "자재그룹 정보",
size: 130,
},
{
accessorKey: "vendorInfo",
header: "협력업체 정보",
size: 130,
},
{
accessorKey: "vendorClassification",
header: "업체분류",
size: 100,
},
{
accessorKey: "faStatus",
header: "FA현황",
size: 100,
},
{
accessorKey: "recentQuoteNumber",
header: "최근견적번호",
size: 130,
},
{
accessorKey: "recentOrderNumber",
header: "최근발주번호",
size: 130,
},
]
// 프로젝트 AVL 테이블 컴포넌트
function ProjectAvlTable({
onSelectionChange,
resetCounter
}: {
onSelectionChange?: (count: number) => void
resetCounter?: number
}) {
const [data] = React.useState(() => [...mockProjectAvlData])
const table = useReactTable({
data,
columns: projectAvlColumns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
initialState: {
pagination: {
pageSize: 10,
},
},
})
// 선택 상태 변경 시 콜백 호출
React.useEffect(() => {
const selectedRows = table.getFilteredSelectedRowModel().rows
onSelectionChange?.(selectedRows.length)
}, [table.getFilteredSelectedRowModel().rows.length, onSelectionChange])
// 선택 해제 요청이 오면 모든 선택 해제
React.useEffect(() => {
if (resetCounter && resetCounter > 0) {
table.toggleAllPageRowsSelected(false)
}
}, [resetCounter, table])
return (
<div className="flex flex-col">
<div className="mb-2">
<div className="flex items-center justify-between mb-2">
<h4 className="font-medium">프로젝트 AVL</h4>
<div className="flex gap-1">
<Button variant="outline" size="sm">
행 추가
</Button>
<Button variant="outline" size="sm">
파일 업로드
</Button>
<Button variant="outline" size="sm">
자동 매핑
</Button>
<Button variant="outline" size="sm">
강제 매핑
</Button>
<Button variant="outline" size="sm">
항목 삭제
</Button>
</div>
</div>
</div>
<DataTable table={table} />
</div>
)
}
// 선종별 표준 AVL 테이블 컴포넌트
function StandardAvlTable({
onSelectionChange,
resetCounter
}: {
onSelectionChange?: (count: number) => void
resetCounter?: number
}) {
const [data] = React.useState(() => [...mockStandardAvlData])
const table = useReactTable({
data,
columns: standardAvlColumns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
initialState: {
pagination: {
pageSize: 10,
},
},
})
// 선택 상태 변경 시 콜백 호출
React.useEffect(() => {
onSelectionChange?.(table.getFilteredSelectedRowModel().rows.length)
}, [table.getFilteredSelectedRowModel().rows.length, onSelectionChange])
// 선택 해제 요청이 오면 모든 선택 해제
React.useEffect(() => {
if (resetCounter && resetCounter > 0) {
table.toggleAllPageRowsSelected(false)
}
}, [resetCounter, table])
return (
<div className="flex flex-col">
<div className="mb-2">
<div className="flex items-center justify-between mb-2">
<h4 className="font-medium">선종별 표준 AVL</h4>
<div className="flex gap-1">
<Button variant="outline" size="sm">
신규업체 추가
</Button>
<Button variant="outline" size="sm">
파일 업로드
</Button>
<Button variant="outline" size="sm">
일괄입력
</Button>
<Button variant="outline" size="sm">
항목삭제
</Button>
</div>
</div>
</div>
<DataTable table={table} />
</div>
)
}
// Vendor Pool 테이블 컴포넌트
function VendorPoolTable({
onSelectionChange,
resetCounter
}: {
onSelectionChange?: (count: number) => void
resetCounter?: number
}) {
const [data] = React.useState(() => [...mockVendorPoolData])
const table = useReactTable({
data,
columns: vendorPoolColumns,
getCoreRowModel: getCoreRowModel(),
getPaginationRowModel: getPaginationRowModel(),
getSortedRowModel: getSortedRowModel(),
getFilteredRowModel: getFilteredRowModel(),
initialState: {
pagination: {
pageSize: 10,
},
},
})
// 선택 상태 변경 시 콜백 호출
React.useEffect(() => {
onSelectionChange?.(table.getFilteredSelectedRowModel().rows.length)
}, [table.getFilteredSelectedRowModel().rows.length, onSelectionChange])
// 선택 해제 요청이 오면 모든 선택 해제
React.useEffect(() => {
if (resetCounter && resetCounter > 0) {
table.toggleAllPageRowsSelected(false)
}
}, [resetCounter, table])
return (
<div className="flex flex-col">
<div className="mb-2">
<div className="flex items-center justify-between mb-2">
<h4 className="font-medium">Vendor Pool</h4>
<div className="flex gap-1">
<Button variant="outline" size="sm">
신규업체 추가
</Button>
</div>
</div>
</div>
<DataTable table={table} />
</div>
)
}
// 선택된 테이블 타입
type SelectedTable = 'project' | 'standard' | 'vendor' | null
// 선택 상태 액션 타입
type SelectionAction =
| { type: 'SELECT_PROJECT'; count: number }
| { type: 'SELECT_STANDARD'; count: number }
| { type: 'SELECT_VENDOR'; count: number }
| { type: 'CLEAR_SELECTION' }
// 선택 상태
interface SelectionState {
selectedTable: SelectedTable
selectedRowCount: number
resetCounters: {
project: number
standard: number
vendor: number
}
}
// 선택 상태 리듀서
const selectionReducer = (state: SelectionState, action: SelectionAction): SelectionState => {
switch (action.type) {
case 'SELECT_PROJECT':
if (action.count > 0) {
return {
selectedTable: 'project',
selectedRowCount: action.count,
resetCounters: {
...state.resetCounters,
standard: state.selectedTable !== 'project' ? state.resetCounters.standard + 1 : state.resetCounters.standard,
vendor: state.selectedTable !== 'project' ? state.resetCounters.vendor + 1 : state.resetCounters.vendor,
}
}
} else if (state.selectedTable === 'project') {
return {
...state,
selectedTable: null,
selectedRowCount: 0,
}
}
return state
case 'SELECT_STANDARD':
if (action.count > 0) {
return {
selectedTable: 'standard',
selectedRowCount: action.count,
resetCounters: {
...state.resetCounters,
project: state.selectedTable !== 'standard' ? state.resetCounters.project + 1 : state.resetCounters.project,
vendor: state.selectedTable !== 'standard' ? state.resetCounters.vendor + 1 : state.resetCounters.vendor,
}
}
} else if (state.selectedTable === 'standard') {
return {
...state,
selectedTable: null,
selectedRowCount: 0,
}
}
return state
case 'SELECT_VENDOR':
if (action.count > 0) {
return {
selectedTable: 'vendor',
selectedRowCount: action.count,
resetCounters: {
...state.resetCounters,
project: state.selectedTable !== 'vendor' ? state.resetCounters.project + 1 : state.resetCounters.project,
standard: state.selectedTable !== 'vendor' ? state.resetCounters.standard + 1 : state.resetCounters.standard,
}
}
} else if (state.selectedTable === 'vendor') {
return {
...state,
selectedTable: null,
selectedRowCount: 0,
}
}
return state
default:
return state
}
}
// AVL 등록 영역 컴포넌트
export function AvlRegistrationArea() {
// 단일 선택 상태 관리 (useReducer 사용)
const [selectionState, dispatch] = React.useReducer(selectionReducer, {
selectedTable: null,
selectedRowCount: 0,
resetCounters: {
project: 0,
standard: 0,
vendor: 0,
},
})
// 선택 핸들러들
const handleProjectSelection = React.useCallback((count: number) => {
dispatch({ type: 'SELECT_PROJECT', count })
}, [])
const handleStandardSelection = React.useCallback((count: number) => {
dispatch({ type: 'SELECT_STANDARD', count })
}, [])
const handleVendorSelection = React.useCallback((count: number) => {
dispatch({ type: 'SELECT_VENDOR', count })
}, [])
const { selectedTable, selectedRowCount, resetCounters } = selectionState
return (
<Card className="h-full min-w-full overflow-visible">
{/* 고정 헤더 영역 */}
<div className="sticky top-0 z-10 p-4 border-b">
<div className="flex items-center justify-between">
<h3 className="text-lg font-semibold">AVL 등록</h3>
<div className="flex gap-2">
<Button variant="outline" size="sm">
저장
</Button>
<Button variant="outline" size="sm">
최종 확정
</Button>
<Button variant="outline" size="sm">
AVL 불러오기
</Button>
</div>
</div>
</div>
{/* 스크롤되는 콘텐츠 영역 */}
<div className="overflow-x-auto overflow-y-hidden">
<div className="grid grid-cols-[2.2fr_2fr_2.5fr] gap-0 min-w-[1200px] w-fit">
{/* 프로젝트 AVL 테이블 - 9개 컬럼 */}
<div className="p-4 border-r relative">
<ProjectAvlTable
onSelectionChange={handleProjectSelection}
resetCounter={resetCounters.project}
/>
{/* 이동 버튼들 - 첫 번째 border 위에 오버레이 */}
<div className="absolute right-0 top-1/2 transform -translate-y-1/2 translate-x-1/2 z-10">
<div className="flex flex-col gap-2 bg-background border rounded-md p-1 shadow-sm">
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="왼쪽으로 이동"
disabled={selectedTable !== 'standard' || selectedRowCount === 0}
>
<ChevronLeft className="w-4 h-4" />
</Button>
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="오른쪽으로 이동"
disabled={selectedTable !== 'project' || selectedRowCount === 0}
>
<ChevronRight className="w-4 h-4" />
</Button>
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="오른쪽으로 이동"
disabled={selectedTable !== 'project' || selectedRowCount === 0}
>
<ChevronsRight className="w-4 h-4" />
</Button>
</div>
</div>
</div>
{/* 선종별 표준 AVL 테이블 - 8개 컬럼 */}
<div className="p-4 border-r relative">
<StandardAvlTable
onSelectionChange={handleStandardSelection}
resetCounter={resetCounters.standard}
/>
{/* 이동 버튼들 - 두 번째 border 위에 오버레이 */}
<div className="absolute right-0 top-1/2 transform -translate-y-1/2 translate-x-1/2 z-10">
<div className="flex flex-col gap-2 bg-background border rounded-md p-1 shadow-sm">
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="왼쪽으로 이동"
disabled={selectedTable !== 'standard' || selectedRowCount === 0}
>
<ChevronLeft className="w-4 h-4" />
</Button>
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="오른쪽으로 이동"
disabled={selectedTable !== 'standard' || selectedRowCount === 0}
>
<ChevronRight className="w-4 h-4" />
</Button>
</div>
</div>
</div>
{/* Vendor Pool 테이블 - 10개 컬럼 */}
<div className="p-4 relative">
<VendorPoolTable
onSelectionChange={handleVendorSelection}
resetCounter={resetCounters.vendor}
/>
{/* 이동 버튼들 - 세 번째 테이블의 왼쪽 border 위에 오버레이 */}
<div className="absolute left-0 top-1/2 transform -translate-y-1/2 -translate-x-1/2 z-10">
<div className="flex flex-col gap-2 bg-background border rounded-md p-1 shadow-sm">
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="왼쪽으로 이동"
disabled={selectedTable !== 'vendor' || selectedRowCount === 0}
>
<ChevronsLeft className="w-4 h-4" />
</Button>
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="왼쪽으로 이동"
disabled={selectedTable !== 'vendor' || selectedRowCount === 0}
>
<ChevronLeft className="w-4 h-4" />
</Button>
<Button
variant="outline"
size="sm"
className="w-8 h-8 p-0"
title="오른쪽으로 이동"
disabled={selectedTable !== 'standard' || selectedRowCount === 0}
>
<ChevronRight className="w-4 h-4" />
</Button>
</div>
</div>
</div>
</div>
</div>
</Card>
)
}
|